package com.du;

import com.du.bean.Person;
import com.du.config.MainConfigLifeCycle;
import com.du.config.MainConfigPropertyValues;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;

/**
 * @author djg
 * @date 2020/11/23
 * @des
 */
public class IOCTestPropertyValue {
    AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(MainConfigPropertyValues.class);
    @Test
    public void test01() {
        printBeans(applicationContext);

        System.out.println("====================");
        Person person = (Person) applicationContext.getBean("person");
        System.out.println(person);


        ConfigurableEnvironment environment = applicationContext.getEnvironment();
        System.out.println(environment.getProperty("person.nickName"));
        //关闭容器,执行销毁方法
        applicationContext.close();

    }

    public void printBeans(AnnotationConfigApplicationContext applicationContext) {
        String[] names = applicationContext.getBeanDefinitionNames();
        for (String name : names) {
            System.out.println(name);
        }
    }
}
